package com.heima.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;

import java.io.IOException;
//拦截所有请求
//@WebFilter(urlPatterns = "/emps")
public class FilterDemo implements Filter {
    //启动时执行一次初始化
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("初始化");
    }
    //每次拦截都执行一次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("放行前逻辑");
        System.out.println("拦截");
        //前置增强
        //放行代码
        filterChain.doFilter(servletRequest,servletResponse);
        System.out.println("放行后逻辑");
        //后置增强
    }
    //服务端断开连接销毁
    @Override
    public void destroy() {
        System.out.println("销毁拦截");
    }
}
